package com.example.system.manager;

import com.example.common.core.constants.CacheConstants;
import com.example.common.redis.service.RedisService;
import com.example.system.model.exam.Exam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * 功能描述:
 *
 * @author Lenovo
 * @date 2025/4/3
 */
@Component
public class ExamCacheManager {
    @Autowired
    private RedisService redisService;

    public void addCache(Exam exam) {
        redisService.leftPushForList(getExamListKet(), exam.getExamId());
        redisService.setCacheObject(getDetailKey(exam.getExamId()), exam);
    }

    public void deleteCache(Long examId) {
        redisService.removeForList(getExamListKet(), examId);
        redisService.deleteObject(getDetailKey(examId));
    }

    private String getExamListKet() {
        return CacheConstants.EXAM_UNFINISHED_LIST;
    }

    private String getDetailKey(Long examId) {
        return CacheConstants.EXAM_DETAIL + examId;
    }
}
